package com.ivanceras.model;

import java.io.Serializable;
import java.util.ArrayList;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Question implements Serializable{
	
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    public Long questionID;
    
    @Persistent 
    public String text;
    
    @Persistent 
    public Long questionnaireID;
    
	@NotPersistent
	public ArrayList<Choice> choiceList = new ArrayList<Choice>();
    
	public Question(){
		
	}
	public Question(String text){
		this.setText(text);
	}
	public void addChoice(String text,boolean isCorrect){
		Choice qchoice = new Choice(text, isCorrect);
		choiceList.add(qchoice);
	}
	public void addChoice(Choice ch){
		choiceList.add(ch);
	}
	public void setText(String text) {
		this.text = text;
	}
	public String getText() {
		return text;
	}
	public void setChoices(ArrayList<Choice> choices){
		choiceList.clear();
		for(Choice choice: choices){
			choiceList.add(choice);
		}
	}
	public ArrayList<Choice> getChoices(){
		return choiceList;
	}
	public void setQuestionnaireID(int questionnaireID){
		this.questionnaireID = new Long(questionnaireID);
	}
}
